package com.thinkTank.oa.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.StringUtil;
import com.thinkTank.oa.base.BaseServiceImpl;
import com.thinkTank.oa.dao.ConfOfAttrMapper;
import com.thinkTank.oa.dao.ConferenceMapper;
import com.thinkTank.oa.dao.PersonMapper;
import com.thinkTank.oa.entity.ConfOfAttr;
import com.thinkTank.oa.entity.Conference;
import com.thinkTank.oa.entity.Person;
import com.thinkTank.oa.service.ConOfAttrService;
import com.thinkTank.oa.service.ConferenceService;

@Transactional
@Service("ConferenceService")
public class ConferenceServiceImpl extends BaseServiceImpl<Conference> implements ConferenceService {

	@Autowired
	private ConfOfAttrMapper confOfAttrMapper;

	@Autowired
	private ConferenceMapper conferenceMapper;

	@Autowired
	private PersonMapper personMapper;
	
	@Autowired
	private ConOfAttrService conofAttrService;
	
	@Autowired
	private ConferenceService confrenceService;

	public ConferenceMapper getConferenceMapper() {
		return (ConferenceMapper) super.getBaseMapper();
	}

	@Autowired
	public void setConferenceMapper(ConferenceMapper conferenceMapper) {
		super.setBaseMapper(conferenceMapper);
	}

	/**
	 * 将新增专家，修改会议相关的中间表和会议表，放在同一个事务里面
	 * 
	 * @param attr
	 * @param rence
	 */
	@Override
	public void update(Person person, ConfOfAttr attr, Conference rence) {
		personMapper.addPerson(person);
		confOfAttrMapper.add(attr);
		conferenceMapper.update(rence);
	}

	/**
	 * 将修改会议相关的中间表和会议表，放在同一个事务里面
	 * 
	 * @param attr
	 * @param rence
	 */
	@Override
	public void update(ConfOfAttr attr, Conference rence) {
		confOfAttrMapper.add(attr);
		conferenceMapper.update(rence);
	}

//	@Override
//	public void deleteByconferenceId(String personId, Conference conference) {
//		confOfAttrMapper.deleteAttrByPersonId(personId);
//		conferenceMapper.update(conference);
//	}


	@Override
	public List<Conference> queryAllConference(Conference conference) {
		
		return conferenceMapper.queryAllConference(conference);
	}
	
	
	/**
	 * 模糊查询会议
	 * @author dongli
	 * @date 2018年8月26日
	 * @param conference
	 * @return
	 */
	public List<Conference> findMConference(Conference conference){
		return conferenceMapper.findMConference(conference);
	}
	
	/**
	 * 通过中间表专家id查询会议
	 * @author dongli
	 * @date 2018年9月29日
	 * @param pid
	 * @return
	 */
	public List<Map<Conference, Conference>> findBothByPersonId(String pid){
		return conferenceMapper.findBothByPersonId(pid);
	}

	//通过专家pid在中间表中查询到多条会议pid并封装进数组中来逐条查询会议内容
	public List<Conference> queryInConferenceIds(Conference conference) {
		return conferenceMapper.queryInConferenceIds(conference);
	}
	
	//通过专家pid在中间表中查询到多条会议pid并封装进数组中来逐条查询会议内容前10条
	public List<Conference> queryInConferenceIdsTop10(Conference conference){
		return conferenceMapper.queryInConferenceIdsTop10(conference);
	}
	
}
